﻿/*
 * 文件名称：
 * 程序员：huangsb
 * 创建时间：2008/05/10
 * 
 * 功能说明：IP配置
 * 
 * 修改人员：
 * 
 * 修改日期：
 * 
 * 修改记录：
 */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Whir.Common.WebHelper;

public partial class Whir_System_Module_Config_IPConfig : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        RoleHelper.IsLogin();    //登录判断

        if (!IsPostBack)
        {
            //string xmlPath = Server.MapPath(Whir.Common.Settings.GetString("XmlPath") + "IPConfig.xml");
            string xmlPath = Server.MapPath("~/" + Whir.Common.Settings.GetString("XmlPath") + "IPConfig.xml");
            Type type = typeof(Whir.Config.Model.IPConfig);
            Whir.Config.Model.IPConfig model = (Whir.Config.Model.IPConfig)Whir.Common.XmlHelper.DeserializeObject(xmlPath, type);         //反序列化

            this.rblLimitWay_all.SelectedValue = model.limitWay_all;
            this.rblLimitWay_back.SelectedValue = model.limitWay_back;

            DataBind1();
            DataBind2();
            DataBind3();
            DataBind4();
        }
    }

    //修改选项
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        Whir.Config.Model.IPConfig model = new Whir.Config.Model.IPConfig();

        model.limitWay_all = this.rblLimitWay_all.SelectedValue;
        model.limitWay_back = this.rblLimitWay_back.SelectedValue;

        //string xmlPath = Server.MapPath(Whir.Common.Settings.GetString("XmlPath") + "IPConfig.xml");
        string xmlPath = Server.MapPath("~/" + Whir.Common.Settings.GetString("XmlPath") + "IPConfig.xml");
        Type type = typeof(Whir.Config.Model.IPConfig);
        Whir.Common.XmlHelper.SerializerObject(xmlPath, type, model);               //序列化

        this.OLAdd();    //操作日志
    }

    //操作日志
    protected void OLAdd()
    {
        Whir.Log.Model.Whir_OperateLog model = new Whir.Log.Model.Whir_OperateLog();
        model.title = "IP设置";
        model.operateType = 2;      //修改
        model.operateResult = true;
        model.operateDesc = "修改IP设置";

        Whir.Log.OperateLog.Add(model);
    }

    #region ip事件
    //绑定1
    protected void DataBind1()
    {
        string sql = "select * from Whir_IP where isAll=1 and isWhite=1";
        DataSet ds = Whir.SQLServerDAL.DbHelperSQL.Query(sql);

        this.rIP1.DataSource = ds;
        this.rIP1.DataBind();

        if (ds.Tables[0].Rows.Count == 0)
            this.div1.Visible = false;
        else
            this.div1.Visible = true;
    }

    //添加1
    protected void btnAdd1_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid)
            return;
        Whir.BLL.Whir_IP bll = new Whir.BLL.Whir_IP();
        Whir.Model.Whir_IP model = new Whir.Model.Whir_IP();
        model.startIP = this.txtStartIP1.Text;
        model.endIP = this.txtEndIP1.Text;
        model.isAll = true;
        model.isWhite = true;

        bll.Add(model);
        JsHelper.redirect(Page, "数据已提交！", "IPConfig.aspx");
    }

    //删除1
    protected void lbnDelete1_Click(object sender, EventArgs e)
    {
        LinkButton lbn = sender as LinkButton;

        Whir.BLL.Whir_IP bll = new Whir.BLL.Whir_IP();
        bll.Delete(int.Parse(lbn.CommandArgument));

        JsHelper.redirect(Page, "数据已删除！", "IPConfig.aspx");
    }

    //绑定2
    protected void DataBind2()
    {
        string sql = "select * from Whir_IP where isAll=1 and isWhite=0";
        DataSet ds = Whir.SQLServerDAL.DbHelperSQL.Query(sql);

        this.rIP2.DataSource = ds;
        this.rIP2.DataBind();

        if (ds.Tables[0].Rows.Count == 0)
            this.div2.Visible = false;
        else
            this.div1.Visible = true;
    }

    //添加2
    protected void btnAdd2_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid)
            return;
        Whir.BLL.Whir_IP bll = new Whir.BLL.Whir_IP();
        Whir.Model.Whir_IP model = new Whir.Model.Whir_IP();

        model.startIP = this.txtStartIP2.Text;
        model.endIP = this.txtEndIP2.Text;
        model.isAll = true;
        model.isWhite = false;

        bll.Add(model);
        JsHelper.redirect(Page, "数据已提交！", "IPConfig.aspx");
    }

    //删除2
    protected void lbnDelete2_Click(object sender, EventArgs e)
    {
        LinkButton lbn = sender as LinkButton;

        Whir.BLL.Whir_IP bll = new Whir.BLL.Whir_IP();
        bll.Delete(int.Parse(lbn.CommandArgument));

        JsHelper.redirect(Page, "数据已删除！", "IPConfig.aspx");
    }

    //绑定3
    protected void DataBind3()
    {
        string sql = "select * from Whir_IP where isAll=0 and isWhite=1";
        DataSet ds = Whir.SQLServerDAL.DbHelperSQL.Query(sql);

        this.rIP3.DataSource = ds;
        this.rIP3.DataBind();

        if (ds.Tables[0].Rows.Count == 0)
            this.div3.Visible = false;
        else
            this.div1.Visible = true;
    }

    //添加3
    protected void btnAdd3_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid)
            return;
        Whir.BLL.Whir_IP bll = new Whir.BLL.Whir_IP();
        Whir.Model.Whir_IP model = new Whir.Model.Whir_IP();

        model.startIP = this.txtStartIP3.Text;
        model.endIP = this.txtEndIP3.Text;
        model.isAll = false;
        model.isWhite = true;

        bll.Add(model);
        JsHelper.redirect(Page, "数据已提交！", "IPConfig.aspx");
    }

    //删除3
    protected void lbnDelete3_Click(object sender, EventArgs e)
    {
        LinkButton lbn = sender as LinkButton;

        Whir.BLL.Whir_IP bll = new Whir.BLL.Whir_IP();
        bll.Delete(int.Parse(lbn.CommandArgument));

        JsHelper.redirect(Page, "数据已删除！", "IPConfig.aspx");
    }

    //绑定4
    protected void DataBind4()
    {
        string sql = "select * from Whir_IP where isAll=0 and isWhite=0";
        DataSet ds = Whir.SQLServerDAL.DbHelperSQL.Query(sql);

        this.rIP4.DataSource = ds;
        this.rIP4.DataBind();

        if (ds.Tables[0].Rows.Count == 0)
            this.div4.Visible = false;
        else
            this.div1.Visible = true;
    }

    //添加4
    protected void btnAdd4_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid)
            return;
        Whir.BLL.Whir_IP bll = new Whir.BLL.Whir_IP();
        Whir.Model.Whir_IP model = new Whir.Model.Whir_IP();

        model.startIP = this.txtStartIP4.Text;
        model.endIP = this.txtEndIP4.Text;
        model.isAll = false;
        model.isWhite = false;

        bll.Add(model);
        JsHelper.redirect(Page, "数据已提交！", "IPConfig.aspx");
    }

    //删除4
    protected void lbnDelete4_Click(object sender, EventArgs e)
    {
        LinkButton lbn = sender as LinkButton;

        Whir.BLL.Whir_IP bll = new Whir.BLL.Whir_IP();
        bll.Delete(int.Parse(lbn.CommandArgument));

        JsHelper.redirect(Page, "数据已删除！", "IPConfig.aspx");
    }
    #endregion
}
